<?php

flep_structure($structure, 'usuario');
$edit = false;

if(isset($_POST['id'])){
    $structure['where'][0] = sprintf("`%s`.`id`='%s'", $structure['table'], flep_decode($_POST['id']));
    $edit = flep_search_all($structure);
}

?><b><?php echo (!$edit?'Nuevo ':'')?>Usuario</b>
  <br><br><br>
  <p class="error" id="e_msg" style="display: none;"></p>
    <form class="save" action="store.php?type=usuario" method="POST" id="form_usuario" onsubmit="flep_check_pass(event, 'clave', 'clave2', 'e_msg');" autocomplete="off">
    <input type="hidden" value="<?php echo ($edit?flep_encode($structure['data'][0]['id']):'')?>" id="id" name="id">
        <table>
            <tr>
                <td><label>Nombre:</label></td>
                <td><input type="text" autofocus name="nombre" style="width: 250px" value="<?php echo ($edit?$structure['data'][0]['nombre']:'')?>" required placeholder="Nombre Completo"></td>
            </tr>
            <tr id="tr_code">
                <td><label>Nombre de Usuario</label></td>
                <td><input type="text" name="usuario" style="width: 200px" value="<?php echo ($edit?$structure['data'][0]['usuario']:'')?>" required placeholder="Usuario"></td>
            </tr>
            <tr>
                <td><label>Contrase&ntilde;a:</label></td>
                <td><input type="password" name="clave" id="clave" style="width: 200px" autocomplete="off" <?php echo ($edit?'':'required')?> placeholder="Min. 6 caracteres"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="password" id="clave2" style="width: 200px" autocomplete="off" <?php echo ($edit?'':'required')?> placeholder="Verificar Contrase&ntilde;a"></td>
            </tr>
            <tr>
                <td><label>Correo Electronico:</label></td>
                <td><input type="email" name="correo" style="width: 250px" value="<?php echo ($edit?$structure['data'][0]['correo']:'')?>" placeholder="Formato: correo@servidor" ></td>
            </tr>
            <tr>
                <td><label>Administrador:</label></td>
                <td><input type="checkbox" name="administrador" value="1" <?php echo ($edit && $structure['data'][0]['administrador'] === '1'? 'checked' :'')?>></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="Guardar" style="margin-right: 100px;"><input type="reset" value="Limpiar"></td>
            </tr>
        </table>
    </form>
